package com.payment.ktb.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.view.PagerAdapter;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.payment.ktb.R;
import com.payment.ktb.activity.ShowH5WithTitleActivity;
import com.payment.ktb.activity.main1.BanKaActivity;
import com.payment.ktb.constants.Constants;
import com.payment.ktb.constants.ConstantsUser;
import com.payment.ktb.model.AdvertisementEntity;
import com.payment.ktb.utils.SharedPreferencesUtils;
import com.ppdai.loan.PPDLoanAgent;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by syd on 2016/5/13.
 */
public class Main1BannerPagerAdapter extends PagerAdapter {




    Context mContext;
    List<AdvertisementEntity> bannerList;

    public Main1BannerPagerAdapter(Context mContext, List<AdvertisementEntity> bannerList) {
        this.mContext = mContext;
        this.bannerList = bannerList;

    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }


    @Override
    public Object instantiateItem(ViewGroup container, final int position) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_fragment1_banner,null);

        ImageView imageView = (ImageView) view.findViewById(R.id.iv_fragment1_banner);
        Picasso.with(mContext).load(bannerList.get(position%bannerList.size()).getAreaPic()).fit().into(imageView);
        container.addView(view);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!TextUtils.isEmpty(bannerList.get(position % bannerList.size()).getAreaHref())) {
                    Intent intent = new Intent(mContext, ShowH5WithTitleActivity.class);
                    intent.putExtra("url",bannerList.get(position % bannerList.size()).getAreaHref());
                    mContext.startActivity(intent);
                }
            }
        });

        return view;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

      container.removeView((View)object);

    }
}
